import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.types.{StructType, StructField, StringType, IntegerType};
import org.apache.spark.sql.Row;
import org.apache.spark.sql.types._
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.types.IntegerType
import org.apache.spark.sql.Row
//scala中没有静态方法和静态成员的说法,object具备了这两种类似的功能.
object AccessConvertUtil 
{
            val struct = StructType(//这里千万注意,Structtype后面的"("绝对不能换行.①
                List(StructField("time",StringType),
                                StructField("url",StringType),
                                StructField("traffic",StringType),
                                StructField("city",StringType)
                              )
            )




            
  /**
    * 根据输入的每一行信息转换成输出的样式
    */
  def parseLog(log:String) = //这里定义成员函数
  {

    try 
    {
      val splits = log.split(" ")
      val time = splits(0).trim
      val url = splits(1).trim
      val traffic = splits(2).trim
      val city =splits(3).trim//②


      //这个Row里面的字段要和struct中的字段对应上

      Row(time,url,traffic,city)//返回Row,③
    } catch {
      case e: Exception => Row(0)
    }

  }

}
//注意,①②③的字段顺序必须严格对应一致.
